﻿Imports CupsApp.Service
Imports CupsApp.Data

Partial Public Class housing
    Inherits System.Web.UI.Page

    Public _service As CupsDomainService
    Public _data As ClientProperty

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _data = New ClientProperty
        _service = New CupsDomainService
        lvlMsg.Text = ""
       
        If Not IsPostBack Then
            If IsNothing(Request.QueryString("clientID")) Then
                CType(Master.FindControl("lnkNewClient"), LinkButton).Enabled = False
                CType(Master.FindControl("lnkNewClient"), LinkButton).Text = "> New Client/Family <"
            Else
                ddLandlordID.DataBind()
                SuitePropertyDataSource.DataBind()
                ddAddress.DataBind()
                Client_ID.Value = Request.QueryString("clientID")
                wwDataBinder1.DataBind()


            End If
        End If

    End Sub

#Region "Click Events"

    Protected Sub lnkPersonal_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkPersonal.Click
        Response.Redirect(String.Format("personal.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkBackground_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkBackground.Click
        Response.Redirect(String.Format("background.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkHealthLegal_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkHealthLegal.Click
        Response.Redirect(String.Format("health_legal.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkFollowUp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkFollowUp.Click
        Response.Redirect(String.Format("follow_up.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkStatus_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkStatus.Click
        Response.Redirect(String.Format("status.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkExit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkExit.Click
        Response.Redirect(String.Format("exit.aspx?clientID={0}", Client_ID.Value))
    End Sub

#End Region

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
        wwDataBinder1.Unbind()

        Try
            _service.UpdateClientProperty(Client_ID.Value, _data)
            lvlMsg.Text = "* Housing information was saved successfully!"

            Page.DataBind()
            lblMsg.Visible = False
        Catch ex As Exception
            lblMsg.Text = "* Unable to save data"
            lblMsg.Visible = True
        End Try

    End Sub

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If (e.CommandName = "Update") Then
            _data = _service.GetClientProperty(e.CommandArgument)
            btnSave.Text = "Update"
            wwDataBinder1.DataBind()
        End If
    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancel.Click
        btnSave.Text = "Save"
        _data = New ClientProperty
    End Sub
End Class